﻿/// <reference path="../../Common/Scripts/jquery.min.js" />
/// <reference path="~/Content/Common/Widget/kindeditor/kindeditor-min.js" />
/// <reference path="../../Common/Widget/jquery-easyui/jquery.easyui.min.js" />

/*公共属于*/
var LogoutPostUrl = "";  //登入验证提交地址
var LoginPageUrl = "";      //登入页面地址
var CultureComboboxJsonData = [{ "id": "zh-cn", "text": "中文", "selected": false }, { "id": "en-us", "text": "English", "selected": false }];

/*显示AJAX表单提交返回信息*/
var AjaxMessage = function (data, fn, errorfn) {
    if (data.state) {
        $.messager.alert('提示', data.message, "info", fn);
    } else {
        $.messager.alert('提示', data.message, "error", errorfn);
    }
};
/* Admin页面初始化 */
/*公共方法*/
/*后台登出*/
var LoginOut = function () {
    $.messager.confirm('系统提示', '您确定要退出本次登录吗?', function (r) {
        if (r) {
            $.ajax({
                url: LogoutPostUrl,
                type: 'Post',
                dataType: 'json',
                timeout: 1000,
                success: function (data) {
                    AjaxMessage(data, function () { location.href = LogoutPostUrl; });
                }
            });
        }
    });
};
/*Tabs 添加TABS方法定义*/
var AddTab = function (title, url, content, remote, refresh) {
    var tab = null;
    var option = {
        title: title,
        closable: true,
        fit: true,
        cache: true

    };
    if (remote) {
        $.extend(option, { href: url });
    } else {
        $.extend(option, { content: content });
    }
    if ($('#main_tabs').tabs('exists', title)) {
        $('#main_tabs').tabs('select', title);
    } else {
        tab = $('#main_tabs').tabs('add', option);
    }
    return tab;
};
/*定义 table 列删除方法*/
var TableDeleteRecord = function (table, url) {
    var rows = $(table).datagrid('getSelections');
    if (!rows || rows.length == 0) {
        $.messager.alert('提示', '请选择要删除的数据');
        return;
    }
    var parm;
    $.each(rows, function (i, n) {
        if (i == 0) {
            parm = "id=" + n.Id;
        } else {
            parm += "&id=" + n.Id;
        }
    });
    $.messager.confirm('提示', '是否删除这些数据?', function (r) {
        if (!r) {
            return;
        }
        $.ajax({
            type: "POST",
            url: url,
            data: parm,
            success: function (msg) {
                if (msg.state) {
                    $.messager.alert('提示', '删除成功！', "info", function () {
                        $(table).datagrid("reload");
                    });
                }
            },
            error: function () {
                $.messager.alert('错误', '删除失败！', "error");
            }
        });
    });
};
/*Table 默认属性定义*/
var TableOptionDefault = $.extend($.fn.datagrid.defaults, { width: 'auto', height: '500', nowrap: false, striped: true, fit: true, remoteSort: true, collapsible: true, fitColumns: true, sortName: 'Sort', sortOrder: 'asc', idField: 'Id', pagination: true, onLoadSuccess: function () { }, onBeforeLoad: function () { $(this).datagrid('rejectChanges'); }, onClickRow: function (rowIndex) { $(this).datagrid("unselectRow", rowIndex); }, onSelect: function (rowIndex, rowData) { } });
/*控制面板默认属性*/
var PanelDefaultOption = $.extend($.fn.panel.defaults, { border: true, cache: false, height: 'auto', loadingMessage: "正在载入..." });
/*window 弹窗默认属性*/
var WindowsDefaultOption = $.extend($.fn.window.defaults, { loadingMessage: "正在载入...", cache: true, modal: false });
/*validatebox 表单验证*/
/*validatebox 表单验证 扩展*/
$.extend($.fn.validatebox.defaults.rules, { equalTo: { validator: function (value, param) { return $(param[0]).val() == value; }, message: '字段不匹配' } });
/*将表单转化为JSON对象*/
$.fn.serializeObject = function () { var o = {}; var a = this.serializeArray(); $.each(a, function () { if (o[this.name]) { if (!o[this.name].push) { o[this.name] = [o[this.name]]; } o[this.name].push(this.value || ''); } else { o[this.name] = this.value || ''; } }); return o; }